﻿
//刷新验证码
function refresh() {
    document.getElementById("captcha").src="Code/getCode.action?A="+new Date();
}
// 校验验证码输入是否正确
function Test1() {
    if ($("#captchaInput").val()!=""){
        var x;
        $.ajax({
            type:"post",
            url:"Code/ExamineCode.action",
            async:false,
            data:{InputResult:$("#captchaInput").val()},
            dataType:"json",
            success:function (message) {
                var code=message.code;
                if (code==0){
                    alert("验证码输入错误，请重新填写");
                    x=false;
                }else{
                    x=true;
                }
            }
        });
        return x;
    }else{
        alert("验证码不能为空");
        return false;
    }
}

function isUser() {
    if ($("#username").val()!=""){
        return true;
    }
    alert("用户名不允许为空")
    return false;
}

function isPassword() {
    if ($("#password").val()!=""){
        return true;
    }
    alert("密码不允许为空")
    return false;
}
//登录
function Login() {
    if (isUser()&&isPassword()&&Test1()){
        $.ajax({
            type: "post",
            url:"common/doLogin.action",
            data:{loginName:$("#username").val(),loginPwd:$("#password").val(),level:$("#level").val(),remenberMe:$("#remenberMe").val()},
            dataType:"json",
            success:function (message) {
                var code=message.code;
                if (code==0){
                    alert("该用户不存在或密码错误");
                }else if(code==3){
                    window.location="/page/admin/adminindex.jsp"
                }else if(code==1){
                    window.location="/page/student/studentindex.jsp"
                }else if(code==2){
                    window.location="/page/teacher/teacherindex.jsp"
                }else if(code==4){
                    alert("该用户已被锁定，请联系管理员");
                }
            }
        });

    }
}
